package com.yun.zf.app.controller;

import com.github.xiaoymin.knife4j.annotations.DynamicParameter;
import com.github.xiaoymin.knife4j.annotations.DynamicParameters;
import com.yun.zf.app.service.ZfFollowService;
import com.yun.zf.common.vo.Response;
import com.yun.zf.system.security.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@Api(tags = "首页")
@RequestMapping("/detail")
@Slf4j
public class DetailController extends BasicController {
    @Autowired
    private ZfFollowService followService;
    @ApiOperation(value = "是否关注")
    @PostMapping("/isFollow")
    @DynamicParameters(properties = {
            @DynamicParameter(name = "houseId",value = "房源编号",example = "1",required = true)
    })
    public Response getHouseDetailInfo(@RequestBody Map<String, String> map) {
        //获取登录信息
        Long userId =  SecurityUtils.getLoginUser().getUserId();
           int c =   followService.hasFollow(userId,Long.parseLong( map.get("houseId")));
            Map<String,String> map1= new HashMap<>();
            if (c>0){
                map1.put("isFollow","true");
            }else {
                map1.put("isFollow","false");
            }
        return Response.success(map1);
    }


}
